<?php
    /**
    * This is mobile connectors
    * For Profile module
    * Contains all required funtions for mobile connectors
    * 
    * @author trungdt
    * @since Dec 10, 2012
    * @copyright ABSoft Viet Nam
    */
    
    if (!defined('EXPONENT')) exit('');
    define("_MOBILE_CONNECTOR_TIMEOUT",15*60);
    
    // check https protocol first
    if (!(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] =="on" ))
        die(); // no http please
    
    global $db;
    
    /********* Functions definition **************/
    function profile_mobile_get_current_clientIP(){
        return $_SERVER['REMOTE_ADDR'];
    }
    
    function profile_mobile_get_current_clientGUIID(){
        return sha1(uniqid(exponent_sessions_getTicketString().profile_mobile_get_current_clientIP()));
    }
    
    function profile_module_updateClientSession_last_response($session_id){
        global $db;
        $msession = $db->selectObject("profilemodule_mobilesession", "session_id = '{$session_id}'");
        if (isset($msession->id))
        {
            $msession->last_response = time();
            $db->updateObject($msession, "profilemodule_mobilesession");
        }
    }
    
    /********* Init *****************************/
    // wipe out timeout session
    $_mobile_connector_now = time()-_MOBILE_CONNECTOR_TIMEOUT;
    $db->delete("profilemodule_mobilesession", "last_response < {$_mobile_connector_now}");
?>